package cn.echo.modules.sys.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by LSF_ on 2017/5/7.
 */
public class SessionFactory {

    public static SessionFactory sessionFactory=new SessionFactory();
    public static SqlSession session;
    public static SqlSessionFactory sqlSessionFactory;



    public void setSessionFactory(){}

    static {
        String file="mybatis-config.xml";
        try {
            InputStream inputStream= Resources.getResourceAsStream(file);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
// 不获取

    public static SqlSession getSession() {
        session=sqlSessionFactory.openSession();
        System.out.println("链接成功！");
        return session;
    }



}
